import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common'
import { MenuService } from './menu.service'
import { CreateMenuDto } from './dto/create-menu.dto'
import { UpdateMenuDto } from './dto/update-menu.dto'
import { ApiTags } from '@nestjs/swagger'

@ApiTags('菜单')
@Controller('menu')
export class MenuController {
  constructor(private readonly menuService: MenuService) {}

  @Post('/create/firstMenu')
  create(@Body() createMenuDto: CreateMenuDto) {
    return this.menuService.createFirstLevelMenu(createMenuDto)
  }

  @Post('/create/secondMenu')
  create2(@Body() createMenu: CreateMenuDto) {
    const { parentId, ...menuData } = createMenu
    return this.menuService.createSecondLevelMenu(parentId, menuData)
  }

  @Get('/getAllAuthList')
  findAll() {
    return this.menuService.findAll()
  }

  @Post('/updateMenu')
  update(@Body() updateMenuDto: UpdateMenuDto) {
    return this.menuService.updateMenu(updateMenuDto)
  }

  @Get('deleteMenu/:id')
  remove(@Param('id') id: string) {
    return this.menuService.removeMenuById(+id)
  }
}
